var constant = require('../../../config/constant');
var config = require('../../../config/system_config');
var Model = require('../../../components/models');
var async = require('async');

module.exports = {
    /**
     * 获取医生待解决和进行中的问题数
     */
    countMyQuestion: function (req, res) {
        var accountId = req.session.account.accountId, now = new Date();
        async.parallel([
            function (callback) {
                // 获取待解决的问题数
                Model.Question.countDocs({
                    answererId: accountId,
                    replyStatus: constant.ReplyStatus.NOT_REPLY,
                    $nor: [
                        {status: constant.QuestionStatus.DELETED},
                        {reportStatus: constant.ReportStatus.REPORTED},
                        {
                            replyStatus: constant.ReplyStatus.NOT_REPLY,
                            status: constant.QuestionStatus.ANSWERING,
                            assignTime: {$lte: now.getTime() - config.answerFailureTime}
                        }
                    ],
                    $or: [{orderStatus: null}, {orderStatus: {$gte: constant.OrderStatus.PAID}}]
                }, callback);
            },
            function (callback) {
                // 获取进行中的问题数
                Model.Question.countDocs({
                    answererId: accountId,
                    replyStatus: constant.ReplyStatus.REPLY,
                    $nor: [
                        {status: constant.QuestionStatus.DELETED},
                        {reportStatus: constant.ReportStatus.REPORTED}
                    ]
                }, callback);
            }
        ], function (err, results) {
            err ? res.createFailure(err) : res.createSuccess({notReply: results[0], reply: results[1]});
        });
    }
};
